import { BasicService } from 'src/app/shared/service/basic.service';
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { PageObject, SongSheet, SheetQueryCriteria } from '../entity';
import { map } from 'rxjs/operators';
import queryString from 'query-string';

@Injectable()
export class SheetListService extends BasicService {

  constructor(private http: HttpClient) {
    super();
  }

  getSheets(queryCriteria: SheetQueryCriteria): Observable<PageObject<SongSheet>> {
    const params = new HttpParams({fromString: queryString.stringify(queryCriteria)});
    const url = this.api(`top/playlist`);
    return this.http.get<any>(url, {params}).pipe(map(res => {
      return {
        content: res.playlists,
        total: res.total
      };
    }));
  }

}
